import { AfterViewChecked, Component, ElementRef, EventEmitter, Injector, Output, ViewChild } from '@angular/core';
import { AppConsts } from '@shared/AppConsts';
import { AppComponentBase } from '@shared/common/app-component-base';
import { ProfileServiceProxy, ProcessingViewDto} from '@shared/service-proxies/service-proxies';
import { ModalDirective } from 'ngx-bootstrap';
import { IOrganizationUnitsTreeComponentData } from '../../shared/organization-unit-tree.component';
import * as _ from 'lodash';
import { finalize } from 'rxjs/operators';
//import { TaskService } from '../../task/Task.service';

@Component({
  selector: 'OrderProcessingSubCreate',
  templateUrl: './OrderProcessingSubCreate.component.html',
  styleUrls: ['./OrderProcessingSubCreate.component.css']
})
export class OrderProcessingSubCreateComponent extends AppComponentBase {

  @ViewChild('createOrEditModal') modal: ModalDirective;
  @Output() modalSave: EventEmitter<any> = new EventEmitter<any>();

  active = false;
  saving = false;
  newdto : ProcessingViewDto;
  _processingViewDto: ProcessingViewDto = new ProcessingViewDto();
  constructor( injector: Injector ) {
    super(injector);
  }

  show(dto: ProcessingViewDto): void {
    console.log(dto);
    this.active = true;
    this._processingViewDto = dto;
    console.log(this._processingViewDto);
    this.modal.show();
  }

  onShown(): void {
    //document.getElementById('Code').focus();
  }

  save(): void {
    // this.outsourcing.quasiTime = 0;
    // this.outsourcing.takeTime = 0;
    // this.outsourcing.taskForModelId = this.task.id;
    // this.outsourcing.picNo = this.task.picNo;
    // this.outsourcing.displayName = this.task.displayName;
    // this.outsourcing.code = this.task.code;
    // this._taskService.addToOutsourcs(this.outsourcing);
    // this.notify.info(this.l('SavedSuccessfully'));
    //this.close();
    // this.modalSave.emit(null);
    console.log(this._processingViewDto)
    this.modal.hide();
  }

  close(): void {
    this.active = false;
    this._processingViewDto.processingAmount = 0;
    this._processingViewDto.processingstatus = '';
    this._processingViewDto.progressrequest = null;
    this._processingViewDto.materialsupply = '';
    this._processingViewDto.unitprice = 0;
    this._processingViewDto.explain = '';
    this.modal.hide();
  }

}
